package com.sugon.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.util.RandomUtil;
import com.sugon.dao.DevMainBaseAmHistoryDao;
import com.sugon.entity.DevMainBaseAmEntity;
import com.sugon.entity.DevMainBaseAmHistoryEntity;
import com.sugon.service.DevMainBaseAmHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 设备维护项变更履历Service实现类
 *
 * @author sugon
 * @date 2020-11-27 10:27:56
 */
@Service("devMainBaseAmHistoryService")
public class DevMainBaseAmHistoryServiceImpl implements DevMainBaseAmHistoryService {
    @Autowired
    private DevMainBaseAmHistoryDao devMainBaseAmHistoryDao;

    /**
     * recordHistory
     * @param actionType  动作类别
     * @param devMainBase 设备维护项详情
     */
    @Override
    public void recordHistory(String actionType, DevMainBaseAmEntity devMainBase) {
        DevMainBaseAmHistoryEntity devMainBaseHistory = new DevMainBaseAmHistoryEntity();
        CopyOptions copyOptions = CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true);
        BeanUtil.copyProperties(devMainBase, devMainBaseHistory, copyOptions);
        devMainBaseHistory.setCode(devMainBase.getCode());
        devMainBaseHistory.setRecordId(devMainBase.getId());
        devMainBaseHistory.setOperator(devMainBase.getUpdateUser());
        devMainBaseHistory.setOperateDate(devMainBase.getUpdateDate());
        devMainBaseHistory.setActionType(actionType);
        save(devMainBaseHistory);
    }

    /**
     * queryObject
     * @param id 主键
     * @return
     */
    @Override
    public DevMainBaseAmHistoryEntity queryObject(String id) {
        return devMainBaseAmHistoryDao.queryObject(id);
    }

    /**
     * queryList
     * @param map 参数
     * @return
     */
    @Override
    public List<DevMainBaseAmHistoryEntity> queryList(Map<String, Object> map) {
        return devMainBaseAmHistoryDao.queryList(map);
    }

    /**
     * queryTotal
     * @param map 参数
     * @return
     */
    @Override
    public int queryTotal(Map<String, Object> map) {
        return devMainBaseAmHistoryDao.queryTotal(map);
    }

    /**
     * save
     * @param devMainBaseHistory 实体
     * @return
     */
    @Override
    public int save(DevMainBaseAmHistoryEntity devMainBaseHistory) {
        devMainBaseHistory.setId(RandomUtil.randomString(32));
        return devMainBaseAmHistoryDao.save(devMainBaseHistory);
    }

    /**
     * update
     * @param devMainBaseHistory 实体
     * @return
     */
    @Override
    public int update(DevMainBaseAmHistoryEntity devMainBaseHistory) {
        return devMainBaseAmHistoryDao.update(devMainBaseHistory);
    }

    /**
     * delete
     * @param id
     * @return
     */
    @Override
    public int delete(String id) {
        return devMainBaseAmHistoryDao.delete(id);
    }

    /**
     * deleteBatch
     * @param ids
     * @return
     */
    @Override
    public int deleteBatch(String[] ids) {
        return devMainBaseAmHistoryDao.deleteBatch(ids);
    }
}
